/*****************************************************************************
 *
 * Copyright (c), 2004-2020,ShangHai Neotune Information Technology Co., Ltd.
 *
 * Module Name : view.h
 *
 * Author :    sean
 *
 * Date :    2004-02-05
 *
 * Version :    1.00
 *
 * Description :    
 *
 * Other :    
 *
 * Data Structure List: <Main Data Structure>
 *
 * Modification History
 * ---------------------------------------------------------------------------
 *  1: Data :      2004-02-05
 *    Author :     sean
 *    Version :    V100R001M00
 *    Modification : creation
 *
*****************************************************************************/

#if (!defined(view_inc))
#define view_inc

#ifdef __cplusplus
extern"C" {
#endif

#if (!defined(snmpdefs_inc))
#include <snmpdefs.h>
#endif

#if (!defined(smi_inc))
#include "smi.h"
#endif

#define STO_OTHER  1
#define STO_VOL    2
#define STO_NONVOL 3
#define STO_PERM   4
#define STO_RONLY  5

#define RS_RSNE    0
#define RS_ACTIVE  1
#define RS_NIS     2
#define RS_NREADY  3
#define RS_CAGO    4
#define RS_CAWAIT  5
#define RS_DESTROY 6

/* define the view structures */
#define VIEW_INCLUDED 1
#define VIEW_EXCLUDED 2
#define VIEW_INDETERMINATE 3
#define VIEW_MAXMASKLEN 16
#define VIEW_MAXINDEX  65535
#define VIEW_MAXINDEXL 65535L

#define ETC_VIEW_NAME_MIN 1
#define ETC_VIEW_NAME_MAX 32

/* options for SNMP_View_Check */
#define VIEW_CHECK_DET   0
#define VIEW_CHECK_IND   1

#ifdef NEOSNET_STRUCT_ALIGN
#pragma align 1
#endif

typedef struct VIEWLEAF_S
        {
        struct VIEWINDEX_S *parent;     /* backpointer to parent, 0 if
                                           this view isn't installed */
        bits16_t        index;          /* index of the view table,
                                           this is the same as it's parents
                                           view index used for admin */
        OBJ_ID_T        subtree;        /* the oid for this subtree */
        EBUFFER_T       mask;           /* wildcard string */
        int             type;           /* is this entry included or exc */
        int             status;         /* status of this entry */
        int             storage;        /* type of storage of this entry */
        struct VIEWLEAF_S *  lexinext;  /* list of leaves in lexi order */
        struct VIEWLEAF_S *  masknext;  /* list of leaves in mask order */
        } VIEWLEAF_T;

typedef struct VIEWINDEX_S
        {
#if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS)
        bits16_t        index;          /* index of the view table */
#endif

#if (INSTALL_ENVOY_SNMP_RFC2275_VIEWS)
        bits8_t     *   name;           /* name of the view table */
        ALENGTH_T       name_len;       /* length of name */
#endif

        struct VIEWINDEX_S *    next;   /* next index in the chain */
        VIEWLEAF_T  *   lexilist;       /* list of leaves in lexi order */
        VIEWLEAF_T  *   masklist;       /* list of leaves in mask order */
        } VIEWINDEX_T;

#ifdef NEOSNET_STRUCT_ALIGN
#pragma align 0
#endif


#if (INSTALL_ENVOY_SNMP_DYNAMIC_VIEWS)
extern int SNMP_ViewFindFamily  __((SNMP_PKT_T *));
extern int SNMP_ViewFamilyCheck __((SNMP_PKT_T *, OIDC_T *, int, int));
extern int SNMP_ViewCheck        __((SNMP_PKT_T *, OIDC_T *, int, int));

#define SNMP_View_Get_Type(V)           ((V)->type)
#define SNMP_View_Set_Type(V, W)        ((V)->type = (bits16_t)W)
#define SNMP_View_Get_Mask(V)           (EBufferStart(&(V)->mask))
#define SNMP_View_Get_MaskLen(V)        (EBufferUsed(&(V)->mask))
#define SNMP_View_Set_StorageType(V, W) ((V)->storage = (bits16_t)W)
#define SNMP_View_Get_StorageType(V)    ((V)->storage)
#define SNMP_View_Set_Status(V, W)      ((V)->status = (bits16_t)W)
#define SNMP_View_Get_Status(V)         ((V)->status)
#define SNMP_View_Get_Subtree(V)        ((V)->subtree.component_list)
#define SNMP_View_Get_Subtree_Len(V)    ((V)->subtree.num_components)

#define SNMP_View_Set_Defaults(V) ((V)->parent    = 0, \
                                   EBufferInitialize(&(V)->mask), \
                                   (V)->masknext = 0, \
                                   (V)->lexinext = 0, \
                                   (V)->type     = VIEW_INCLUDED, \
                                   (V)->storage  = STO_NONVOL, \
                                   (V)->status   = RS_NIS)


extern VIEWLEAF_T *SNMP_View_Create        __((OIDC_T *, int));
extern void        SNMP_View_Delete        __((VIEWLEAF_T *));
extern VIEWLEAF_T *SNMP_View_Next          __((VIEWLEAF_T *));
extern int         SNMP_View_Set_Mask      __((VIEWLEAF_T *, bits8_t *, int));

#if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS)
#define SNMP_View_Get_Index(V)   ((V)->index)

extern int         SNMP_View_Install       __((bits16_t, VIEWLEAF_T *)); 
extern int         SNMP_View_Name          __((VIEWLEAF_T *, bits16_t *,
                                               OIDC_T *, int));
extern int         SNMP_View_Deinstall     __((bits16_t, OIDC_T *, int));
extern VIEWLEAF_T *SNMP_View_Lookup        __((bits16_t, OIDC_T *, int));
#endif /* #if (INSTALL_ENVOY_SNMP_RFC1445_VIEWS) */

#if (INSTALL_ENVOY_SNMP_RFC2275_VIEWS)
/*#define SNMP_View_2275_Name(V)     ((V)->parent ? (V)->parent->name : 0)
#define SNMP_View_2275_Name_Len(V) ((V)->parent ? (V)->parent->name_len : 0)*/

extern void        SNMP_View_2275_Name       __((VIEWLEAF_T *, bits8_t *,
                                                 ALENGTH_T *));
extern int         SNMP_View_2275_Install    __((VIEWLEAF_T *, bits8_t *,
                                                 ALENGTH_T));
extern int         SNMP_View_2275_Full_Name  __((VIEWLEAF_T *, OIDC_T *, int));
extern void        SNMP_View_2275_Deinstall  __((VIEWLEAF_T *));
extern VIEWLEAF_T *SNMP_View_2275_Lookup     __((bits8_t *, ALENGTH_T,
                                                 OIDC_T *, int)); 
extern sbits32_t   v3_vacmViewSpinLock;
#endif /* #if (INSTALL_ENVOY_SNMP_RFC2275_VIEWS) */


extern void        viewtable_test          __((OIDC_T, int, OIDC_T *,
                                               SNMP_PKT_T *, VB_T *));

extern void        viewtable_get           __((OIDC_T, int, OIDC_T *,
                                               SNMP_PKT_T *, VB_T *));

extern void        viewtable_next          __((OIDC_T, int, OIDC_T *,
                                               SNMP_PKT_T *, VB_T *));

extern void        viewtable_set           __((OIDC_T, int, OIDC_T *,
                                               SNMP_PKT_T *, VB_T *));

#endif /* (INSTALL_ENVOY_SNMP_DYNAMIC_VIEWS) */

extern VIEWINDEX_T *viewroot;

#ifdef __cplusplus
}
#endif

#endif /* view_inc */

